<?php

namespace iBrand\Shop\Core\Models;

use Illuminate\Database\Eloquent\Model;

class ShopOrder extends Model
{
	protected $guarded = ['id'];

	protected $appends = ['value_yuan'];

	public function __construct(array $attributes = [])
	{
		parent::__construct($attributes);

		$prefix = config('ibrand.app.database.prefix', 'ibrand_');

		$this->setTable($prefix . 'o2o_shop_order');
	}

	public function clerk()
	{
		return $this->hasOne(Clerk::class, 'id', 'clerk_id')->withDefault();
	}

	public function order()
	{
		return $this->belongsTo(Order::class, 'order_id', 'id');
	}

	public function getValueYuanAttribute()
	{
		if ($this->value == null) {
			return 0;
		}

		return number_format($this->value / 100, 2, ".", "");
	}



	public function shop()
	{
		return $this->belongsTo(Shop::class, 'shop_id');
	}

}

